$(function () {
    $("#billhistory_datagrid").datagrid({
        fit: true,
        url: '/guaranteebill/queryHistory',
        columns: [[
            {field: 'id', title: 'id', width: 100, hidden: true}, //hidden 隐藏显示该列
            {field: 'number', title: '保险单号', width: 100},//允许列改变大小
            {
                field: 'applicant', title: '投保人', width: 100,
                formatter: function (value, row, index) {
                    return value.name;
                }
            },
            {field: 'carinfo', title: '车牌号', width: 100,
                formatter: function (value, row, index) {
                    return value.carnum;
                }},
            {field: 'vdate', title: '申请日期', width: 100},
            {field: 'auditdate', title: '核保日期', width: 100},
            {field: 'begindate', title: '起保日期', width: 100},
            {field: 'enddate', title: '止保日期', width: 100},
            {field: 'limityear', title: '保险时长', width: 100},
            {
                field: 'op', title: '业务员', width: 100,
                formatter: function (value, row, index) {
                    return value.username;
                }
            },
            {
                field: 'audit', title: '审核人', width: 100,
                formatter: function (value, row, index) {
                    return value.username;
                }
            },
            {field: 'totalprice', title: '投保总金额', width: 100},
            {
                field: 'state', title: '状态', width: 100,
                formatter: function (value, row, index) {
                    if (value == 4) {
                        return "<font style='color: red'>已审核未交费</font>";
                    } else if (value == 5) {
                        return "<font style='color: green'>已交费</font>";
                    }
                }
            }
        ]],
        rownumbers: true,
        striped: true,
        toolbar: "#billhistory_toolbar",
        pagination: true,
        fitColumns: true,
        singleSelect:true
    })


    //刷新
    $("#reload").click(function () {
        $("#billhistory_datagrid").datagrid("reload");
    })

    //高级查询
    $("#query").click(function () {
        var applicant = $("#applicant").textbox("getValue");
        var number = $("#number").textbox("getValue");
        $("#billhistory_datagrid").datagrid("load", {
            applicant: applicant,
            number: number
        })
    })



    /** ====================================保单查看弹出框=================================== */
    $("#showBill").click(function () {
        //编辑方法
        var row = $("#billhistory_datagrid").datagrid("getSelected");
        if (!row) {
            $.messager.alert("温馨提示", '至少选择一条数据', 'warning');
            return;
        }
        var carId = row.carinfo.id;
        console.log(carId)
        $("#carinfo_form").form("load", "/guaranteebill/queryCarInfo?carId="+carId)
        $("#edit_dialog").dialog('open');
        $("#edit_dialog").dialog('center');

    });
    //初始化弹窗
    $("#edit_dialog").dialog({
        closed: true,
        title: '查看保单信息',
        width: 800,
        height: 300,
        buttons: '#showInfo_buttons',
    });

    //点击关闭事件
    $("#showInfo_cancel").click(function () {
        $("#show_dialog").dialog("close");
    });

})











